package visiopuce.action;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import org.apache.commons.lang.StringEscapeUtils;
import org.eclipse.jface.action.Action;

import visiopuce.ICommandIds;

public class ModifieBaseAction extends Action {

	public ModifieBaseAction(String text) {
		super(text);
		// The id is used to refer to the action in a menu or toolbar
		setId(ICommandIds.CMD_MODIFIE_BASE);
		// Associate the action with a pre-defined command, to allow key
		// bindings.
		setActionDefinitionId(ICommandIds.CMD_MODIFIE_BASE);
		setText("Moifier les fichiers sql");
		setToolTipText("Modifiersql");
		setImageDescriptor(visiopuce.Activator.getImageDescriptor("/icons/switch-user.png"));
	}

	public void run() {


		InputStream ips;
		try {
			ips = new FileInputStream("C:/Users/Manon/Documents/workspace visiopuce2/visiopuce/visiopuce.sql");

			InputStreamReader ipsr = new InputStreamReader(ips,"utf8");
			BufferedReader br = new BufferedReader(ipsr);
			String lu;
			FileOutputStream ops = new FileOutputStream("C:/Users/Manon/Documents/workspace visiopuce2/visiopuce/visiopuceunescapeHtml.sql");
			
	
			BufferedWriter output = new BufferedWriter(new OutputStreamWriter(ops, "utf-8"));
			while ((lu = br.readLine()) != null) {
				
				output.write(StringEscapeUtils.unescapeHtml(lu));
			}
			output.flush();
			output.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}